package com.yinhe.music.yhmusic.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.v7.widget.AppCompatImageView;
import android.util.AttributeSet;

import com.yinhe.music.yhmusic.R;

public class CommentView extends AppCompatImageView {

    private Paint mPaint;
    private int count = -1;
    private String colorString = "#af316f";

    public CommentView(Context context) {
        super(context);
        init();
    }

    public CommentView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public CommentView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }


    public void setUnreadCount(int count) {
        this.count = count;
        invalidate();
    }

    public void setColorString(String colorString) {
        this.colorString = colorString;
        invalidate();
    }

    private void init() {
        mPaint = new Paint(Paint.FAKE_BOLD_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
        mPaint.setAntiAlias(true);

        mPaint.setTextSize(getResources().getDimensionPixelSize(R.dimen.comment_text_size));
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        mPaint.setColor(Color.parseColor(colorString));

        if (this.count >= 0) {
            int baseLineX = getWidth() / 2 + getResources().getDimensionPixelSize(R.dimen.dp_2);
            int baseLineY = getHeight() / 2 - getResources().getDimensionPixelSize(R.dimen.dp_3);
            //画基线
            canvas.drawText("" + count, baseLineX, baseLineY, mPaint);
        }
    }
}

